package com.dt76.smallloanbackenduser.controller.xiaohao;

import com.dt76.smallloanbackenduser.pojo.xiaohao.BorrowOrder;
import com.dt76.smallloanbackenduser.pojo.xiaohao.CheckState;
import com.dt76.smallloanbackenduser.remote.xiaohao.BorrowOrderRemote;
import com.dt76.smallloanbackenduser.remote.xiaohao.CheckStateRemote;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class CheckStateController {

    @Resource
    private CheckStateRemote checkStateRemote;
    @Resource
    private BorrowOrderRemote borrowOrderRemote;

    @RequestMapping("/checkState/add")
    @ResponseBody
    public Boolean checkStateAdd(CheckState checkState, String csboID){
        Boolean result = false;
        //代表是终审
        System.out.println(checkState.getmResult());
        System.out.println(csboID);
        checkState.setmType(3);
        //给审核记录加上订单号
        checkState.setBoId(Long.parseLong(csboID));
        //根据订单ID查询订单
        BorrowOrder borrowOrder = borrowOrderRemote.qryByID(Integer.parseInt(csboID));
        //更新订单状态
        borrowOrder.setBoType(checkState.getmResult());

        borrowOrderRemote.modifyBorrowOrderType(borrowOrder);
        //添加审核记录
        int i = checkStateRemote.addCheckState(checkState);
        if(i>0){
            result = true;
        }
        return result;
    }

    @RequestMapping("/checkState/query")
    @ResponseBody
    public Map<String,Object> qryCheckStateById(String boId){
        Map<String,Object> map = new HashMap<>();
        List<CheckState> checkStates = checkStateRemote.qryAllCheckStateByID(Integer.parseInt(boId));
        for (CheckState checkState:checkStates) {
            System.out.println(checkState.toString());
        }
        map.put("checkStates",checkStates);
        return map;
    }
}
